//
//  YQTabBarViewController.swift
//  WeiBO
//
//  Created by a on 16/2/29.
//  Copyright © 2016年 xinji. All rights reserved.
//

import UIKit

class YQTabBarViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
//        tabBar  = YQTabBar 为只读的属性不能直接的赋值可以通过kvc来实现赋值
        
        let myTabBar = YQTabBar()
        
        setValue(myTabBar, forKey: "tabBar")
        
        myTabBar.composeButton.addTarget(self, action: "composeBunttonClick", forControlEvents: UIControlEvents.TouchUpInside)
        
        addChildViewController()
        
    }
    
    
    func composeBunttonClick(){
        print("点我了")
    }
    
    /**
     添加自控制器
     */
    func addChildViewController()->Void {
        
        addChildViewController(YQHomeViewController(), imageName: "tabbar_home", title: "首页")
        addChildViewController(YQMessageViewController(), imageName: "tabbar_message_center", title: "消息")
        addChildViewController(YQFindViewController(), imageName: "tabbar_discover", title: "发现")
        addChildViewController(YQSettingViewController(), imageName: "tabbar_profile", title: "设置")
        
        
    }
    
    func addChildViewController(childController: UIViewController,imageName:String,title:String) {
        
        childController.title = title
        //设置其下方的图片
        childController.tabBarItem.image = UIImage(named: imageName)
        //设置其选中的图片
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_highlighted")
        //改变其渲染的颜色
        //添加到TabBar上面去
        addChildViewController(UINavigationController(rootViewController:childController))
    }

}
